package com.itggm.Result;

import lombok.Data;

import java.util.HashMap;

/**
 * @author 课工场
 * @date 2024/12/18
 * @description
 */
@Data
public class ResponseResult {

    private Integer code;
    private String message;
    private HashMap<String,Object> data = new HashMap<>();


    // 业务成功
    public  static ResponseResult success(){
        ResponseResult responseResult = new ResponseResult();
        responseResult.code = ResponseStatus.SUCCESS.getCode();
        responseResult.message = ResponseStatus.SUCCESS.getMessage();
        return  responseResult;
    }


    // 业务失败
    public  static ResponseResult fail(){
        ResponseResult responseResult = new ResponseResult();
        responseResult.message = ResponseStatus.FAIL.getMessage();
        responseResult.code =ResponseStatus.FAIL.getCode();
        return  responseResult;
    }


    // 系统异常
    public  static ResponseResult error(){
        ResponseResult responseResult = new ResponseResult();
        responseResult.code = ResponseStatus.ERROR.getCode();
        responseResult.message = ResponseStatus.ERROR.getMessage();
        return  responseResult;
    }


    public ResponseResult code(ResponseStatus responseStatus){
        this.code = responseStatus.getCode();
        return this;
    }

    public ResponseResult message(String message){
        this.message = message;
        return this;
    }

    public ResponseResult data(String key,Object value){
        this.data.put(key,value);
        return this;
    }


    public static void main(String[] args) {


        ResponseResult data1 = ResponseResult.success().data("total", 1000).data("tableData", new HashMap<>());
        System.out.println("data1 = " + data1);


    }

}
